package com.kk.travel.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.kk.travel.service.UserService;

public class SingleFilter implements Filter {

    public SingleFilter() {
        // TODO Auto-generated constructor stub
    }

	public void destroy() {
		System.out.println("destory");
		// TODO Auto-generated method stub
	}

	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

		System.out.println("dofilter");
		HttpServletRequest req=(HttpServletRequest) request;
		HttpSession session=req.getSession();
		
		
		if(session.getAttribute("words")==null){
			session.setAttribute("words", new UserService().getWords());
		}		

		
		chain.doFilter(request, response);
	}


	public void init(FilterConfig fConfig) throws ServletException {
		System.out.println("init");
		

	}

}
